const express = require('express');
const router = express.Router();
const sql = require('../sql/index')
const Pro = require('../sql/collection/Pro')

router.get('/', function (req, res, next) {
    res.send('搜索')
});
/**
* @api {get} /api/search/pro 搜索商品
* @apiName GetApiPro
* @apiGroup Search
* 
* @apiParam { String } keyword 搜索关键字
*
* @apiSuccessExample { json } Success-Response:
    res.send({
            code: "200",
            message: "搜索商品",
            data
        })
* @apiSampleRequest /api/search/pro
* @apiVersion 0.0.0
*/
// 搜索商品
router.get("/pro", (req, res, next) => {
    const { keyword } = req.query;
    const reg = new RegExp(keyword);
    sql.find(Pro, { $or: [{ proname: reg }, { info: reg }]}, { _id: 0 }).then((data) => {
        res.send({
            code: "200",
            message: "搜索商品",
            data
        })
    })
})
module.exports = router;
